<template>
	<!-- 我的建议 -->

	<view class="content">
		<!-- 建议列表 begin -->
		<view class="news">
			<view class="search">
				<!-- 输入框前边的图标 -->
				<uni-icons class="search-icon" type="search" />
				<!-- 输入框 -->
				<input class="inputInnner" placeholder="搜索关键字" />
				<!-- 确认按钮  -->
				<view class="verifbtn flexcent">
					搜索
				</view>
			</view>
			<!-- tab begin -->
			<view class="tabbar">
				<view class="item" v-for="(item, index) in tabList" :key="index" :class="{ active: tabIndex === index }"
					@tap="switchTab(index)">
					{{ item }}
					<view class="underline" :style="{ background: tabIndex === index ? '#ad2325' : '' }"></view>
				</view>
			</view>
			<!-- tab end -->
			<swiper :current="tabIndex" :duration="300" :show-scrollbar="false"
				:style="{ height: swiperHeight + 'px' }">
				<swiper-item v-for="(item, index) in tabList" :key="index">
					<!-- 用户建议列表 begin -->
					<view class="content-item user-advise-list" v-if="index === 0" :id="`swiper_content_id_${index}`">
						<view class="row">
							<view class="grid" @tap="openMyAdviseDetail">
								<view class="user-info">
									<view class="info">
										<image src="/static/img/mine/defalut-avatar.png" class="avatar"></image>
										<view class="base-info">
											<view class="name">张三</view>
											<view class="time">
												2023.12.10
											</view>
										</view>
									</view>
									<view class="register">
										　正式立案
									</view>
								</view>
								<view class="title">
									关于大力发展养殖业产业的提案
								</view>
								<view class="detail">
									<view>提案人：邹玉龙，职务，18805525555</view>
									<view>内容：近年来，随着农村经济扶持力度的持续加大，养殖企业不断发展增多，大力发展养殖产业，…</view>
								</view>
							</view>
							<view class="grid">
								<view class="user-info">
									<view class="info">
										<image src="/static/img/mine/defalut-avatar.png" class="avatar"></image>
										<view class="base-info">
											<view class="name">张三</view>
											<view class="time">
												2023.12.10
											</view>
										</view>
									</view>
									<view class="register">
										　正式立案
									</view>
								</view>
								<view class="title">
									关于大力发展养殖业产业的提案
								</view>
								<view class="detail">
									<view>提案人：邹玉龙，职务，18805525555</view>
									<view>内容：近年来，随着农村经济扶持力度的持续加大，养殖企业不断发展增多，大力发展养殖产业，…</view>
								</view>
							</view>
							<view class="grid">
								<view class="user-info">
									<view class="info">
										<image src="/static/img/mine/defalut-avatar.png" class="avatar"></image>
										<view class="base-info">
											<view class="name">张三</view>
											<view class="time">
												2023.12.10
											</view>
										</view>
									</view>
									<view class="register">
										　正式立案
									</view>
								</view>
								<view class="title">
									关于大力发展养殖业产业的提案
								</view>
								<view class="detail">
									<view>提案人：邹玉龙，职务，18805525555</view>
									<view>内容：近年来，随着农村经济扶持力度的持续加大，养殖企业不断发展增多，大力发展养殖产业，…</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 用户建议列表 end -->
					<!-- 新闻列表 begin -->
					<view class="content-item news-list" v-else :id="`swiper_content_id_${index}`">
						<view class="row">
							<view class="grid-one" @tap="openNewsDetail">
								<view class="img">
									<image src="/static/img/home/news-1.png"></image>
								</view>
								<view class="info">
									<view class="title">
										新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇 {{ index }}
									</view>
								</view>
							</view>
							<view class="grid" @tap="openNewsDetail">
								<view class="img">
									<image src="/static/img/home/news-1.png"></image>
								</view>
								<view class="info">
									<view class="title">
										新城区人大代表热议政府工作报告：扬奋进之帆 谱发展新篇 {{ index }}
									</view>
									<view class="time">2024.02.06 13：50</view>
								</view>
							</view>
							<view class="grid">
								<view class="img">
									<image src="/static/img/home/news-2.png"></image>
								</view>
								<view class="info">
									<view class="title">
										内蒙古自治区十四届人大二次会议开幕 孙绍骋主持王莉霞作… {{ index }}
									</view>
									<view class="time">2024.02.06 13：50</view>
								</view>
							</view>
							<view class="grid">
								<view class="img">
									<image src="/static/img/home/news-2.png"></image>
								</view>
								<view class="info">
									<view class="title">
										内蒙古自治区十四届人大二次会议开幕 孙绍骋主持王莉霞作… {{ index }}
									</view>
									<view class="time">2024.02.06 13：50</view>
								</view>
							</view>
						</view>
					</view>
					<!-- 新闻列表 end -->
				</swiper-item>
			</swiper>
		</view>
		<!-- 建议列表 end -->
	</view>
</template>

<script>
	// import search from '@/components/form/search.vue';

	export default {
		// components: {
		//     search
		// },
		data() {
			return {
				swiperHeight: 0,
				tabIndex: 0,
				tabList: [
					"最新建议",
					"我发起的",
					"我联名的",
					"本届建议",
					"学习园地",
					"公示公告",
					"书香政协",
					"视察调查",
				]
			}
		},
		onLoad() {
			// this.boardcast = await this.$api('boardcast')
			this.setSwiperHeight(0);
		},
		methods: {
			openMyAdviseDetail() {
				uni.navigateTo({
					url: '/pages/committee/home/my-advise-detail'
				})
			},
			openNewsDetail() {
				uni.navigateTo({
					url: '/pages/committee/home/news-detail'
				})
			},
			switchTab(index) {
				if (this.tabIndex === index) return;
				this.tabIndex = index;
				this.setSwiperHeight(index);
			},
			setSwiperHeight(index) {
				this.$nextTick(() => {
					const query = uni.createSelectorQuery().in(this);
					query.select('#swiper_content_id_' + index).boundingClientRect((rect) => {
						if (rect && rect.height > 0) {
							this.swiperHeight = rect.height + 30 + 15;
						} else {
							console.error('Failed to get the container\'s bounding client rectangle');
						}
					}).exec();
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 20rpx;
	}

	// 封装的input输入框
	.search {
		display: flex;
		align-items: center;
		width: 100%;
		// padding: 10rpx;
		background-color: $bg-color-white;
		border-radius: 30rpx;

		// 输入框前边的图标
		.search-icon {
			opacity: 0.8;
			margin: 0 20rpx;
			font-size: 36rpx !important;
			color: #ababab !important;
		}

		// 输入框
		.inputInnner {
			flex: 1;
			height: 100%;
			font-size: 28rpx;
		}

		// 验证码按钮
		.verifbtn {
			height: 30rpx;
			background: #ad2325;
			padding: 15rpx;
			font-size: 28rpx;
			color: #FFF;
			padding: 30rpx;
			border-radius: 30rpx;
			margin-left: 30rpx;

			view {
				width: 140rpx;
				text-align-last: justify;
			}
		}
	}

	.tabbar {
		display: flex;
		overflow-x: auto;
		white-space: nowrap;
		-webkit-overflow-scrolling: touch;
		padding: 20rpx 0;

		.item {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: $font-size-lg;
			padding: 0 10rpx;
		}

		.underline {
			width: 40%;
			height: 6rpx;
			margin-top: 10rpx;
			// background: #ad2325;
			border-radius: 15px
		}

		.active {
			color: #ad2325;
		}
	}

	.content-item {
		width: 100%;
		// padding: 20rpx 40rpx;
		border-radius: $border-radius-lg;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 20rpx;

			.title {
				font-size: $font-size-lg;
				font-weight: 500;
			}

			.subtitle {
				font-size: $font-size-base;
				color: $text-color-grey;
			}
		}

		.row {
			display: flex;
			flex-wrap: wrap;

			.grid {
				width: 25%;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin: 10rpx 0;
				// padding: 20rpx;

				image {
					width: 70rpx;
					height: 70rpx;
					margin-bottom: $spacing-row-base;
				}

				.title {
					font-size: $font-size-base;
					color: $text-color-base;
					display: flex;
					align-items: baseline;
				}
			}
		}
	}

	/deep/ .uni-scroll-view {
		height: auto;
	}

	/deep/ .uni-scroll-view-content {
		height: auto;
	}

	.news-list {
		.grid {
			width: 100% !important;
		}

		.row {
			// height: 100%;
			height: auto;
			margin: 40rpx 0;

			.grid-one {
				flex-direction: unset;
				align-items: start;
				background-color: $bg-color-white;
				// padding: 20rpx 0;
				// padding: 30rpx;
				border-radius: $border-radius-lg;
				margin: 10rpx 0;

				image {
					width: 100%;
					height: 200px;
					border-radius: $border-radius-lg;
				}

				.title {
					// align-items: center;
					font-size: $font-size-lg;
					padding: 20rpx;
				}
			}

			.grid {
				flex-direction: unset;
				align-items: start;
				background-color: $bg-color-white;
				// padding: 20rpx 0;
				padding: 30rpx;
				// border-bottom: 1rpx solid #c7c7c7;
				border-radius: $border-radius-lg;

				.img {
					width: 180rpx;
					height: 150rpx;
					margin-bottom: 0;
				}

				image {
					width: 180rpx;
					height: 150rpx;
					margin-bottom: 0;
					border-radius: $border-radius-lg;
				}

				.info {
					margin: 10rpx 0 10rpx 30rpx;
				}

				.title {
					// font-size: $font-size-lg;
					align-items: center;
					// padding: 20rpx;
				}

				.time {
					margin-top: 20rpx;
					color: #ababab;
				}

				.view {
					display: flex;
					flex-direction: column;
					align-items: center;
					width: 100%;
					/* height: 100%; */
					background-color: rgba(255, 255, 255, 0.6);
					padding: 10rpx 0;
				}
			}
		}
	}

	.user-advise-list {
		.row {
			.grid {
				width: 100%;
				flex-direction: column;
				align-items: start;
				background-color: $bg-color-white;
				// padding: 20rpx 0;
				padding: 30rpx;
				// border-bottom: 1rpx solid #c7c7c7;
				border-radius: $border-radius-lg;

				.user-info {
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;

					.avatar {
						width: 100rpx;
						height: 100rpx;
						border-radius: $border-radius-circle;
						background: #e6e6e6;
					}

					.info {
						display: flex;

						.base-info {
							margin-top: 10rpx;
							margin-left: 30rpx;

							.name {
								font-size: $font-size-lg;
							}

							.time {
								margin-top: 10rpx;
								color: #ababab;
							}
						}
					}

					.register {
						color: #ad2325;
						padding: 10rpx 32rpx;
						// margin: 10rpx 0;
						background: linear-gradient(to right, #fbe2dc, #f4c0b7);
						border-radius: 40rpx;
					}
				}

				.title {
					width: 100%;
					padding: 20rpx 0;
					font-size: $font-size-lg;
					border-bottom: 1px solid #c7c7c7;
				}

				.detail {
					padding: 10rpx 0;
					color: #707070;

					view {
						padding: 10rpx 0;
					}
				}
			}
		}
	}
</style>